package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ebook.entity.Ebook;
import cn.ebook.enume.ErrorEnum;
import cn.ebook.service.dao.impl.EbookServiceImpl;
import cn.ebook.util.DateFactory;
import cn.ebook.util.GsonUtil;
import cn.ebook.util.VoUtil;
import cn.ebook.vo.WebVo;

public class SetServelt extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8;");
		PrintWriter out = response.getWriter();
		//获取参数
		String ebookidstr=request.getParameter("bookid");
		String categoryidstr=request.getParameter("categoryid");
		String title=request.getParameter("title");
		String summary=request.getParameter("summary");
		String uploadMan=request.getParameter("uploadMan");
		String datestr=request.getParameter("date");
		//校验参数
		//略
		
		Long ebookId=new Long(ebookidstr);
		Long categoryId=new Long(categoryidstr);
		
			Date date=DateFactory.DateStr2Date(datestr);
	
		
		Ebook ebook=new Ebook();
		ebook.setId(ebookId);
		ebook.setCategoryId(categoryId);
		ebook.setTitle(title);
		ebook.setSummary(summary);
		ebook.setUploadUser(uploadMan);
		ebook.setCreateDate(date);
		
		
		//调用service
		EbookServiceImpl e=new EbookServiceImpl();
		Boolean bo=e.update(ebook);
		//处理结果
		WebVo vo=null;
		if(bo){
			vo=VoUtil.getSuccess(null);
		}else{
			vo=VoUtil.getErro(ErrorEnum.EBOOK_Set_Fail);
		}
		//封装
		String json=GsonUtil.getJson(vo);
		//响应
		out.write(json);
		out.flush();
		out.close();
	}

}
